package org.lilred.nzbberry.http.cookie;

import java.util.Hashtable;

import org.lilred.nzbberry.http.URL;
import org.lilred.nzbberry.http.cookie.HttpCookie;

public class CookieStore extends Hashtable {
	/**
	 * The internal hashtable representing the cookie store.  The key is the domain
	 * and the value is a DomainCookies object.
	 */
	private Hashtable _cookies = new Hashtable();

	/**
	 * Add a new cookie to the store
	 * @param DownloadedCookie cookie the cookie to add
	 */
	public void addCookie(HttpCookie cookie) {
		//Check to see if a DomainCookies object exits for this domain
		String domain = cookie.getRequestURL().getGenericDomain();
		if (_cookies.get(domain) == null) {
			_cookies.put(domain, new CookieClump());
			System.out.println("Created new CookieClump object for domain: " + cookie.getDomain());
		}
		((CookieClump) _cookies.get(domain)).addCookie(cookie);
	}

	public CookieClump getCookies(URL url) {
		return (CookieClump) _cookies.get(url.getGenericDomain());
	}
}
